#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   SessionControl_0x10_test.py
@Time    :   2022/07/06 13:31:28
@Author  :   **** 
@Version :   1.0
@Contact :   ****@chengtech.com
@License :   (C)Copyright 2022-2025
@Desc    :   None
'''
# here put the import lib
from pytest_assume.plugin import assume
import os
import sys
import logging
curPath = os.path.abspath(os.path.dirname(__file__))
rootPath = os.path.abspath(os.path.dirname(curPath) + os.path.sep + ".")
sys.path.append(rootPath)
sys.path.append(os.path.join(rootPath,'commDriver'))
sys.path.append(os.path.join(rootPath,'data'))
sys.path.append(os.path.join(rootPath,'download'))
logging.info(sys.path)
print(sys.path)


import pytest
import logging
import time
import requests
from sympy import I
# from sympy import assuming
import allure
import sys
from collections.abc import Iterable
from commDriver.modbus_plc import *
from DownLoad import *

from sqlalchemy import false
sys.dont_write_bytecode = True

zipfile_path = Set_up.zipfile_path
error_path = Set_up.error_path


'''Need config plc on conftest.py'''
port ='COM4'
canh_vbat = 0x0000
canh_gnd = 0x0001
canh_canl = 0x0002
canh_open = 0x0003


class Test_Flash(object):
    '''
    The test is used to verification flash
    '''
    @allure.severity('normal')
    @allure.story('Flash Test')
    @allure.title('用例标题：正常工作电压刷写')
    @allure.testcase('https://chengtech.pingcode.com/wiki/spaces/628c37376b65208b0b9ad5bd/pages/62fbb7bc93be72e3501569ff')
    @allure.description('Update program by normal voltage, flash success!')
    # @pytest.mark.skip()
    @pytest.mark.repeat(1)
    def test_normal_voltage_flash(self,action,Driver):                   
        """ 
            @param              :    description
            @action             :    mark the start and end of the test step, import from conftest
            @Driver             :    called but not excuted, import from conftest
        """
        with allure.step('Flash on normal voltage'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            dl.join()
            with assume: assert dl.success_flag == True
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：高电压刷写')
    @allure.description('Update program by high voltage, flash failed!')
    def test_high_voltage_flash(self,action,Driver):                    
        with allure.step('Flash on high voltage'):
            Driver['power'].set_vltage(18.8)
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            dl.join()
            with assume: assert dl.success_flag == False
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：连续多次刷写')
    @allure.description('Repeat update program, flash pass!')
    @pytest.mark.repeat(5)
    def test_repeat_flash(self,action,Driver):                  
        with allure.step('Repeat flash'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            dl.join()
            with assume: assert dl.success_flag == True
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：数据传输到10%中断')
    @allure.description('Flash abnormal termination when transmit 10%, flash failed!')
    def test_data_transfer_10_percent_termination(self,action,Driver):                   
        with allure.step('flash ternination when tansimit 10%'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            i = 0
            while True:
                i +=1
                if (dl.app == True) and (dl.progress_number >= 10):
                    dl.set_stop(True)
                    break
                else:
                    time.sleep(1)
                if i == 1:
                    progress_number = dl.progress_number 
                if i > 80 and dl.progress_number == progress_number:
                    dl.set_stop(True)
                    break
            dl.join()
            with assume: assert dl.success_flag == False
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：数据传输到30%中断')
    @allure.description('Flash abnormal termination when transmit 30%, flash failed!')
    def test_data_transfer_30_percent_termination(self,action,Driver):                 
        with allure.step('flash ternination when tansimit 30%'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            i = 0
            while True:
                i +=1
                if (dl.app == True) and (dl.progress_number >= 30):
                    dl.set_stop(True)
                    break
                else:
                    time.sleep(1)
                if i == 1:
                    progress_number = dl.progress_number 
                if i > 80 and dl.progress_number == progress_number:
                    dl.set_stop(True)
                    break
            dl.join()
            with assume: assert dl.success_flag == False
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：数据传输到50%中断')
    @allure.description('Flash abnormal termination when transmit 50%, flash failed!')
    def test_data_transfer_50_percent_termination(self,action,Driver):                   
        with allure.step('flash ternination when tansimit 50%'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            i = 0
            while True:
                i +=1
                if (dl.app == True) and (dl.progress_number >= 50):
                    dl.set_stop(True)
                    break
                else:
                    time.sleep(1)
                if i == 1:
                    progress_number = dl.progress_number 
                if i > 80 and dl.progress_number == progress_number:
                    dl.set_stop(True)
                    break
            time.sleep(1)
            dl.join()
            with assume: assert dl.success_flag == False
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：数据传输到70%中断')
    @allure.description('Flash abnormal termination when transmit 70%, flash failed!')
    def test_data_transfer_70_percent_termination(self,action,Driver):                      
        with allure.step('flash ternination when tansimit 70%'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            i = 0
            while True:
                i +=1
                if (dl.app == True) and (dl.progress_number >= 70):
                    dl.set_stop(True)
                    break
                else:
                    time.sleep(1)
                if i == 1:
                    progress_number = dl.progress_number 
                if i > 80 and dl.progress_number == progress_number:
                    dl.set_stop(True)
                    break
            dl.join()
            with assume: assert dl.success_flag == False
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：数据传输到90%中断')
    @allure.description('Flash abnormal termination when transmit 90%, flash failed!')
    def test_data_transfer_90_percent_termination(self,action,Driver):                      
        with allure.step('flash ternination when tansimit 90%'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            i = 0
            while True:
                i +=1
                if (dl.app == True) and (dl.progress_number >= 90):
                    dl.set_stop(True)
                    break
                else:
                    time.sleep(1)
                if i == 1:
                    progress_number = dl.progress_number 
                if i > 80 and dl.progress_number == progress_number:
                    dl.set_stop(True)
                    break
            dl.join()
            with assume: assert dl.success_flag == False
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：数据传输中掉电_30%')
    @allure.description('Flash abnormal termination by poweroff when transmit 30%, flash failed!')
    def test_data_transfer_30_percent_poweroff(self,action,Driver):                      
        with allure.step('power off when tansimit 30%'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            i = 0
            while True:
                i += 1
                if (dl.app == True) and (dl.progress_number >= 30):
                    Driver['power'].set_vltage(0)
                    break
                else:
                    time.sleep(1)
                if i == 1:
                    progress_number = dl.progress_number 
                if i > 80 and dl.progress_number == progress_number:
                    dl.set_stop(True)
                    break
            dl.join()
            with assume: assert dl.success_flag == False
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：数据传输中CANL短接Vbat_30%')
    @allure.description('Flash abnormal termination by short CANH and Vbat when transmit 30%, flash failed!')
    # @pytest.mark.skip()
    def test_data_transfer_30_percent_short_canhtovbat(self,action,Driver):                   
        with allure.step('Short CANL and Vbat when tansimit 30%'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            i = 0
            while True:
                i+=1
                if (dl.app == True) and (dl.progress_number >= 30):
                    Driver['CAN'].V_ConnectCanL_Vcc(True, 1)          #Short CANL and Vbat
                    break
                else:
                    time.sleep(1)

                if i == 1:
                    progress_number = dl.progress_number 
                if i > 80 and dl.progress_number == progress_number:
                    dl.set_stop(True)
                    break
            dl.join()
            with assume: assert dl.success_flag == False
            Driver['CAN'].V_ConnectCanL_Vcc(False, 2)          #Open CANL and Vbat
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：数据传输中CANH短接GND_30%')
    @allure.description('Flash abnormal termination by short CANH and GND when transmit 30%, flash failed!')
    # @pytest.mark.skip()
    def test_data_transfer_30_percent_short_canhtognd(self,action,Driver):                   
        with allure.step('Short CANH and GND when tansimit 30%'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            i = 0
            while True:
                i+=1
                if (dl.app == True) and (dl.progress_number >= 30):
                    Driver['CAN'].V_ConnectCanH_GND(True, 1)          #Short CANH and GND
                    break
                else:
                    time.sleep(1)
                if i == 1:
                    progress_number = dl.progress_number 
                if i > 80 and dl.progress_number == progress_number:
                    dl.set_stop(True)
                    break
            dl.join()
            with assume: assert dl.success_flag == False
            Driver['CAN'].V_ConnectCanH_GND(False, 2)          #Open CANH and GND
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：数据传输中CANH短接CANL_30%')
    @allure.description('Flash abnormal termination by short CANH and CANL when transmit 30%, flash failed!')
    # @pytest.mark.skip()
    def test_data_transfer_30_percent_short_canhtocanl(self,action,Driver):                   
        with allure.step('Short CANH and CANL when tansimit 30%'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            i = 0
            while True:
                i += 1
                if (dl.app == True) and (dl.progress_number >= 30):
                    Driver['CAN'].V_ConnectCanH_CanL(True, 1)          #Short CANH and CANL
                    break
                else:
                    time.sleep(1)
                if i == 1:
                    progress_number = dl.progress_number 
                if i > 80 and dl.progress_number == progress_number:
                    dl.set_stop(True)
                    break
            dl.join()
            with assume: assert dl.success_flag == False
            Driver['CAN'].V_ConnectCanH_CanL(False, 2)          #Open CANH and CANL
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    # @allure.severity('normal')
    # @allure.title('用例标题：数据传输中CANH断开_30%')
    # @allure.description('Flash abnormal termination by open CANH when transmit 30%, flash failed!')
    # @pytest.mark.skip()
    # def test_data_transfer_30_percent_open_canh(self,action,Driver):               
    #     with allure.step('Open CANH when tansimit 30%'):
    #         erash_startaddress = [0x00,0x05,0x00,0x00]
    #         erash_size = [0x00,0x08,0x4A,0x96]
    #         dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
    #         i = 0
    #         while True:
    #             i+=1
    #             if (dl.app == True) and (dl.progress_number >= 30):
    #                 Driver['PLC'].write_single_coil(canh_open,0x0000)          #Open CANH
    #                 break
    #             else:
    #                 time.sleep(1)
    #             if i == 1:
    #                 progress_number = dl.progress_number 
    #             if i > 15 and dl.progress_number == progress_number:
    #                 dl.set_stop(True)
    #                 break
    #         dl.join()
    #         with assume: assert dl.success_flag == False
    #         Driver['PLC'].write_single_coil(canh_open,0xFF00)          #Close CANH
    #         self.restartMrr(Driver)
    #         dl.post_abnormal_termination_startup()
    #         with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：内存擦除前掉电')
    @allure.description('Power off befor erash memory, flash failed!')
    def test_poweroff_befor_erash_memory(self,action,Driver):                   
        with allure.step('Power off befor erash memory'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            i = 0
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            while True:
                i += 1
                if (dl.app == True) and (dl.erashing == False):                     #擦除内存前的时间状态
                    Driver['power'].set_vltage(0)
                    logging.info('set power status to off')
                    break
                else:
                    time.sleep(0.5)
                if i > 80:
                    dl.set_stop(True)  
                    break
            dl.join()
            with assume: assert dl.success_flag == False
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：内存擦除前CANL短接Vbat')
    @allure.description('Short CANH and Vbat befor erash memory, flash failed!')
    # @pytest.mark.skip()
    def test_short_canhtovbat_befor_erash_memory(self,action,Driver):                   
        with allure.step('Short CANH and Vbat befor erash memory'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            i = 0
            while True:
                if (dl.app == True) and (dl.erashing == False):                         #擦除内存前的时间状态
                    Driver['CAN'].V_ConnectCanL_Vcc(True, 1)         #Short CANL and Vbat
                    break
                else:
                    time.sleep(0.5)
                if i > 80:
                    dl.set_stop(True)  
                    break
                i += 1
            dl.join()
            with assume: assert dl.success_flag == False
            Driver['CAN'].V_ConnectCanL_Vcc(False, 1)          #Open CANL and Vbat
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    
    @allure.severity('normal')
    @allure.title('用例标题：内存擦除前CANH短接GND')
    @allure.description('Short CANH and GND befor erash memory, flash failed!')
    # @pytest.mark.skip()
    def test_short_canhtognd_befor_erash_memory(self,action,Driver):                   
        with allure.step('Short CANH and GND befor erash memory'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            i = 0
            while True:
                i += 1
                if (dl.app == True) and (dl.erashing == False):                         #擦除内存前的时间状态
                    Driver['CAN'].V_ConnectCanH_GND(True, 1)          #Short CANH and GND
                    break
                else:
                    time.sleep(0.5)
                if i > 80:
                    dl.set_stop(True)  
                    break
            dl.join()
            with assume: assert dl.success_flag == False
            Driver['CAN'].V_ConnectCanH_GND(False, 2)          #Open CANH and GND
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：内存擦除前CANH短接CANL')
    @allure.description('Short CANH and CANL befor erash memory, flash failed!')
    # @pytest.mark.skip()
    def test_short_canhtocanl_befor_erash_memory(self,action,Driver):                   
        with allure.step('Short CANH and CANL befor erash memory'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            i = 0
            while True:
                i += 1
                if (dl.app == True) and (dl.erashing == False):                         #擦除内存前的时间状态
                    Driver['CAN'].V_ConnectCanH_CanL(True, 1)           #Short CANH and CANL
                    break
                else:
                    time.sleep(0.5)
                if i > 80:
                    dl.set_stop(True)  
                    break
            dl.join()
            with assume: assert dl.success_flag == False
            Driver['CAN'].V_ConnectCanH_CanL(False, 2)          #Open CANH and GND
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    # @allure.severity('normal')
    # @allure.title('用例标题：内存擦除前CANH断开')
    # @allure.description('Open CANH befor erash memory, flash failed!')
    # @pytest.mark.skip()
    # def test_open_canh_befor_erash_memory(self,action,Driver):                   
    #     with allure.step('Open CANH befor erash memory'):
    #         erash_startaddress = [0x00,0x05,0x00,0x00]
    #         erash_size = [0x00,0x08,0x4A,0x96]
    #         dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
    #         while True:
    #             if (dl.app == True) and (dl.erashing == False):                         #擦除内存前的时间状态
    #                 Driver['PLC'].write_single_coil(canh_open,0x0000)          #Open CANH
    #                 break
    #             else:
    #                 time.sleep(0.5)
    #         dl.join()
    #         with assume: assert dl.success_flag == False
    #         Driver['power'].set_vltage(0)
    #         Driver['PLC'].write_single_coil(canh_open,0xFF00)          #Close CANH
    #         time.sleep(1)
    #         Driver['power'].set_vltage(14)
    #         time.sleep(3)
    #         dl.post_abnormal_termination_startup()
    #         with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：内存擦除中掉电')
    @allure.description('Power off on erash memory, flash failed!')
    def test_poweroff_erash_memory(self,action,Driver):                      
        with allure.step('Power off on erash memory'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            i = 0
            while True:
                i += 1
                if (dl.app == True) and (dl.erashing == True):                     #擦除内存中的时间状态
                    Driver['power'].set_vltage(0)
                    logging.info('set power status to off')
                    break
                else:
                    time.sleep(0.5)
                if i > 80:
                    dl.set_stop(True)  
                    break
            dl.join()
            with assume: assert dl.success_flag == False
            self.restartMrr(Driver)
            time.sleep(3)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：内存擦除中CANL短接Vbat')
    @allure.description('Short CANH and Vbat on erash memory, flash failed!')
    # @pytest.mark.skip()
    def test_short_canhtovbat_erash_memory(self,action,Driver):                   
        with allure.step('Short CANH and Vbat on erash memory'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            i = 0
            while True:
                i += 1
                if (dl.app == True) and (dl.erashing == True):                         #擦除内存中的时间状态
                    Driver['CAN'].V_ConnectCanL_Vcc(True, 1)           #Short CANL and Vbat
                    break
                else:
                    time.sleep(0.5)
                if i > 80:
                    dl.set_stop(True)  
                    break
            dl.join()
            with assume: assert dl.success_flag == False
            Driver['CAN'].V_ConnectCanL_Vcc(False, 2)                   #Open CANL and Vbat
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：内存擦除中CANH短接GND')
    @allure.description('Short CANH and GND on erash memory, flash failed!')
    # @pytest.mark.skip()
    def test_short_canhtognd_erash_memory(self,action,Driver):                   
        with allure.step('Short CANH and GND on erash memory'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            i = 0
            while True:
                i += 1
                if (dl.app == True) and (dl.erashing == True):                         #擦除内存中的时间状态
                    Driver['CAN'].V_ConnectCanH_GND(True, 1)           #Short CANH and GND
                    break
                else:
                    time.sleep(0.5)
                if i > 80:
                    dl.set_stop(True)  
                    break
            dl.join()
            with assume: assert dl.success_flag == False
            Driver['CAN'].V_ConnectCanH_GND(False, 2)           #Open CANH and GND
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：内存擦除中CANH短接CANL')
    @allure.description('Short CANH and CANL on erash memory, flash failed!')
    # @pytest.mark.skip()
    def test_short_canhtocanl_erash_memory(self,action,Driver):                   
        with allure.step('Short CANH and CANL on erash memory'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            i = 0
            while True:
                i += 1
                if (dl.app == True) and (dl.erashing == True):                         #擦除内存中的时间状态
                    Driver['CAN'].V_ConnectCanH_CanL(True, 1)           #Short CANH and CANL
                    break
                else:
                    time.sleep(0.5)
                if i > 80:
                    dl.set_stop(True)  
                    break

            dl.join()
            with assume: assert dl.success_flag == False
            Driver['CAN'].V_ConnectCanH_CanL(False, 2)                   #Open CANH and CANL
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    # @allure.severity('normal')
    # @allure.title('用例标题：内存擦除中CANH断开')
    # @allure.description('Open CANH on erash memory, flash failed!')
    # @pytest.mark.skip()
    # def test_open_canh_erash_memory(self,action,Driver):                   
    #     with allure.step('Open CANH on erash memory'):
    #         erash_startaddress = [0x00,0x05,0x00,0x00]
    #         erash_size = [0x00,0x08,0x4A,0x96]
    #         dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
    #         while True:
    #             if (dl.app == True) and (dl.erashing == True):                         #擦除内存中的时间状态
    #                 Driver['PLC'].write_single_coil(canh_open,0x0000)          #Open CANH
    #                 break
    #             else:
    #                 time.sleep(0.5)
    #         dl.join()
    #         with assume: assert dl.success_flag == False
    #         Driver['power'].set_vltage(0)
    #         Driver['PLC'].write_single_coil(canh_open,0xFF00)          #Close CANH
    #         time.sleep(1)
    #         Driver['power'].set_vltage(14)
    #         time.sleep(3)
    #         dl.post_abnormal_termination_startup()
    #         with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：故障测试后在正常刷写一次')                             #描述歧义
    @allure.description('Flash after fault test , flash failed!')
    def test_flash_after_fault(self,action,Driver):  
        Driver['power'].set_vltage(18.8)
        Driver['UDS'].reqID = Set_UP.AFctID
        Driver['UDS'].req_and_res_can([0x19,0x02,0x09],3)
        Driver['power'].set_vltage(12)
        with allure.step('Flash after fault test'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            dl.join()
            with assume: assert dl.success_flag == True
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：内存擦除后退出')                             
    @allure.description('Flash by invalid app , flash failed!')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/62fc94a1cfaa81dc60bed3f3/cases')
    def test_Exit_after_erash_memory(self,action,Driver):                   
        with allure.step('Flash by invalid app test'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            i = 0
            while True:
                i += 1
                if (dl.app == True) and (dl.erashing == True):                         #擦除内存中的时间状态
                    dl.set_stop(True)                                                   #停止刷新
                    break
                else:
                    time.sleep(0.5)
                if i > 80:
                    dl.set_stop(True)  
                    break
            dl.join()
            with assume: assert dl.success_flag == False
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：正常进入bootloader模式后退出bootloader模式')                             
    @allure.description('Flash by exit bootloader mode , flash failed!')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/62fc94a1cfaa81dc60bed3f3/cases')
    def test_exit_bootloader_mode(self,action,Driver):                   
        with allure.step('Flash by exit bootloader test'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size,exit=True)
            dl.join()
            with assume: assert dl.success_flag == False
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    
    @allure.severity('normal')
    @allure.title('用例标题：CRC校验错误测试')                             
    @allure.description('Flash by CRC Check Error , flash failed!')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/62fc94a1cfaa81dc60bed3f3/cases')
    def test_crc_error(self,action,Driver):                       
        with allure.step('Flash by CRC Error'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size,crcerror=True)
            dl.join()
            with assume: assert dl.success_flag == False
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：功能寻址TP报文对下载影响')                             
    @allure.description('Flash by Function TP , flash failed!')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/62fc94a1cfaa81dc60bed3f3/cases')
    def test_function_tp(self,action,Driver):                       
        with allure.step('Flash by Function TP'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            i = 0
            while dl.finish == False:
                i += 1
                if dl.app == True:
                    logging.info('Send UDS ID : [0x7DF], the send data are <<<0x3E, 0x80>>>')
                    Driver['CAN'].send_Frame(0x7DF,[0x02, 0x3E, 0x80], 'CAN')
                time.sleep(0.5)
                if i > 800:
                    dl.set_stop(True)  
                    break
            dl.join()
            with assume: assert dl.success_flag == True
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：跳过编程预条件检查')                             
    @allure.description('Flash by skip precheck , flash failed!')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/62fc94a1cfaa81dc60bed3f3/cases')
    def test_skip_precheck(self,action,Driver):                       
        with allure.step('Flash by ship precheck'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size,skipprecheck=True)
            dl.join()
            with assume: assert dl.success_flag == False
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：跳过Flash Driver下载')                             
    @allure.description('Flash by skip Flash Driver , flash failed!')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/62fc94a1cfaa81dc60bed3f3/cases')
    def test_skip_flashdriver(self,action,Driver):                   
        with allure.step('Flash by ship Flash Driver'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size,skipflash=True)
            dl.join()
            with assume: assert dl.success_flag == False
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.story('Flash Test')
    @allure.title('用例标题：升级错误的软件')
    @allure.testcase('https://chengtech.pingcode.com/wiki/spaces/628c37376b65208b0b9ad5bd/pages/62fbb7bc93be72e3501569ff')
    @allure.description('Update program by normal voltage, flash success!')
    def test_failed_soft_flash(self,action,Driver):                   
        """ 
            @param              :    description
            @action             :    mark the start and end of the test step, import from conftest
            @Driver             :    called but not excuted, import from conftest
        """
        with allure.step('Flash on normal voltage'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],error_path,erash_startaddress,erash_size)
            dl.join()
            with assume: assert dl.success_flag == False
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.title('用例标题：只升级boot')                             
    @allure.description('only Flash boot, flash failed!')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/62fc94a1cfaa81dc60bed3f3/cases')
    def test_only_update_boot(self,action,Driver):                   
        with allure.step('Flash by ship Flash Driver'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size,skipapp=True)
            dl.join()
            with assume: assert dl.success_flag == True
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True


    @allure.severity('normal')
    @allure.title('用例标题：只升级boot')                             
    @allure.description('only Flash app, flash failed!')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/62fc94a1cfaa81dc60bed3f3/cases')
    def test_only_update_app(self,action,Driver):                   
        with allure.step('Flash by ship Flash Driver'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size,skipboot=True)
            dl.join()
            with assume: assert dl.success_flag == True
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True


    @allure.severity('normal')
    @allure.story('Flash Test')
    @allure.title('用例标题：升级错误的软件')
    @allure.testcase('https://chengtech.pingcode.com/wiki/spaces/628c37376b65208b0b9ad5bd/pages/62fbb7bc93be72e3501569ff')
    @allure.description('Update program by normal voltage, flash success!')
    def test_errorApp_TrueBoot_flash(self,action,Driver):                   
        """ 
            @param              :    description
            @action             :    mark the start and end of the test step, import from conftest
            @Driver             :    called but not excuted, import from conftest
        """
        with allure.step('Flash on normal voltage'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size,errorApp=True)
            dl.join()
            with assume: assert dl.success_flag == False
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    @allure.severity('normal')
    @allure.story('Flash Test')
    @allure.title('用例标题：升级错误的软件')
    @allure.testcase('https://chengtech.pingcode.com/wiki/spaces/628c37376b65208b0b9ad5bd/pages/62fbb7bc93be72e3501569ff')
    @allure.description('Update program by normal voltage, flash success!')
    def test_TrueApp_errorBoot_flash(self,action,Driver):                   
        """ 
            @param              :    description
            @action             :    mark the start and end of the test step, import from conftest
            @Driver             :    called but not excuted, import from conftest
        """
        with allure.step('Flash on normal voltage'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size,errorBoot=True)
            dl.join()
            with assume: assert dl.success_flag == False
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    
    @allure.severity('normal')
    @allure.story('Flash Test')
    @allure.title('用例标题：降级升级后检查CAN通信再次升级新软件')
    @allure.testcase('https://chengtech.pingcode.com/wiki/spaces/628c37376b65208b0b9ad5bd/pages/62fbb7bc93be72e3501569ff')
    @allure.description('Update program by normal voltage after downgrade program, flash success!')
    def test_downgrade_flash(self,action,Driver):                   
        """ 
            @param              :    description
            @action             :    mark the start and end of the test step, import from conftest
            @Driver             :    called but not excuted, import from conftest
        """
        iStep = 1
        with allure.step('Downgrade on normal voltage'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],Set_up.oldzipfile_path,erash_startaddress,erash_size,skiprestart = True)
            dl.join()
            with assume: assert dl.success_flag == True
            # self.restartMrr(Driver)
            # dl.post_abnormal_termination_startup()
            # with assume: assert dl.normal == False

        time.sleep(1)
        Driver['CAN'].checkReqResp(Driver, "2E F1 A1 FF FF FF FF FF FF FF FF", '6E F1 A1', 3, iStep, True)
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '2E 21 00 ' + Set_up.VariantCoding[0], '6E 21 00', 0, iStep, False)

        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '22 21 00', '62 21 00 ' + Set_up.VariantCoding[0], 0, iStep, False) 

        self.restartMrr(Driver)

        with allure.step('Flash on normal voltage'):
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size)
            dl.join()
            with assume: assert dl.success_flag == True
            self.restartMrr(Driver)
            dl.post_abnormal_termination_startup()
            with assume: assert dl.normal == True

    

    ###烧录新增用例###
    @allure.severity('normal')
    @allure.title('用例标题：APP数据传输到10%中断后发送1101')
    @allure.description('send 1101 after APP transfer termination')
    def test_App_transfer_termination_1101(self,action,Driver):                   
        with allure.step('flash ternination when tansimit 10%'):
            iStep = 0
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size, skipboot=True,isContinue=False)
            i = 0
            while True:
                i +=1
                if (dl.app == True) and (dl.progress_number >= 10):
                    dl.set_stop(True)
                    break
                else:
                    time.sleep(1)
                if i == 1:
                    progress_number = dl.progress_number 
                if i > 80 and dl.progress_number == progress_number:
                    dl.set_stop(True)
                    break
            dl.join()

            iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '11 01', '51 01', 0, iStep)
            with assume: assert size > 0

            logging.info('Wait 30 seconds')
            time.sleep(30)
            dl.post_abnormal_termination_startup()

            self.checkPcanSignal(Driver)

            self.test_normal_voltage_flash(action,Driver)

    @allure.severity('normal')
    @allure.title('用例标题：APP数据传输到10%中断后发送1001')
    @allure.description('send 1001 after APP transfer termination')
    @pytest.mark.repeat(10)
    def test_App_transfer_termination_1001(self,action,Driver):                   
        with allure.step('flash ternination when tansimit 10%'):
            iStep = 0
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size, skipboot=True,isContinue=False)
            i = 0
            while True:
                i +=1
                if (dl.app == True) and (dl.progress_number >= 10):
                    dl.set_stop(True)
                    break
                else:
                    time.sleep(1)
                if i == 1:
                    progress_number = dl.progress_number 
                if i > 80 and dl.progress_number == progress_number:
                    dl.set_stop(True)
                    break
            dl.join()

            iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 01', '50 01', 0, iStep)
            with assume: assert size > 0

            logging.info('Wait 30 seconds')
            time.sleep(30)
            dl.post_abnormal_termination_startup()

            self.checkPcanSignal(Driver)

            self.test_normal_voltage_flash(action,Driver)

    
    @allure.severity('normal')
    @allure.title('用例标题：APP数据传输到10%中断后发送1002')
    @allure.description('send 1002 after APP transfer termination')
    def test_App_transfer_termination_1002(self,action,Driver):                   
        with allure.step('flash ternination when tansimit 10%'):
            iStep = 0
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size, skipboot=True,isContinue=False)
            i = 0
            while True:
                i +=1
                if (dl.app == True) and (dl.progress_number >= 10):
                    dl.set_stop(True)
                    break
                else:
                    time.sleep(1)
                if i == 1:
                    progress_number = dl.progress_number 
                if i > 80 and dl.progress_number == progress_number:
                    dl.set_stop(True)
                    break
            dl.join()

            iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 02', '50 02', 0, iStep)
            with assume: assert size > 0

            logging.info('Wait 30 seconds')
            time.sleep(30)
            dl.post_abnormal_termination_startup()

            self.checkPcanSignal(Driver)

            self.test_normal_voltage_flash(action,Driver)

    
    @allure.severity('normal')
    @allure.title('用例标题：APP数据传输到10%中断后发送1003')
    @allure.description('send 1003 after APP transfer termination')
    def test_App_transfer_termination_1003(self,action,Driver):                   
        with allure.step('flash ternination when tansimit 10%'):
            iStep = 0
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size, skipboot=True,isContinue=False)
            i = 0
            while True:
                i +=1
                if (dl.app == True) and (dl.progress_number >= 10):
                    dl.set_stop(True)
                    break
                else:
                    time.sleep(1)
                if i == 1:
                    progress_number = dl.progress_number 
                if i > 80 and dl.progress_number == progress_number:
                    dl.set_stop(True)
                    break
            dl.join()

            iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 03', '7F 10 7E', 0, iStep)
            with assume: assert size > 0

            logging.info('Wait 30 seconds')
            time.sleep(30)
            dl.post_abnormal_termination_startup()

            self.checkPcanSignal(Driver)

            self.test_normal_voltage_flash(action,Driver)


    
    @allure.severity('normal')
    @allure.title('用例标题：Boot数据传输到10%中断后发送1101')
    @allure.description('send 1101 after Boot transfer termination')
    def test_Boot_transfer_termination_1101(self,action,Driver):                   
        with allure.step('flash ternination when tansimit 10%'):
            iStep = 0
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size, skipapp=True,isContinue=False)
            i = 0
            while True:
                i +=1
                if (dl.app == True) and (dl.progress_number >= 10):
                    dl.set_stop(True)
                    break
                else:
                    time.sleep(1)
                if i == 1:
                    progress_number = dl.progress_number 
                if i > 80 and dl.progress_number == progress_number:
                    dl.set_stop(True)
                    break
            dl.join()

            iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '11 01', '51 01', 0, iStep)
            with assume: assert size > 0

            logging.info('Wait 30 seconds')
            time.sleep(30)
            dl.post_abnormal_termination_startup()

            self.checkPcanSignal(Driver)

            self.test_normal_voltage_flash(action,Driver)

    @allure.severity('normal')
    @allure.title('用例标题：Boot数据传输到10%中断后发送1001')
    @allure.description('send 1001 after Boot transfer termination')
    def test_Boot_transfer_termination_1001(self,action,Driver):                   
        with allure.step('flash ternination when tansimit 10%'):
            iStep = 0
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size, skipapp=True,isContinue=False)
            i = 0
            while True:
                i +=1
                if (dl.app == True) and (dl.progress_number >= 10):
                    dl.set_stop(True)
                    break
                else:
                    time.sleep(1)
                if i == 1:
                    progress_number = dl.progress_number 
                if i > 80 and dl.progress_number == progress_number:
                    dl.set_stop(True)
                    break
            dl.join()

            iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 01', '50 01', 0, iStep)
            with assume: assert size > 0

            logging.info('Wait 30 seconds')
            time.sleep(30)
            dl.post_abnormal_termination_startup()

            self.checkPcanSignal(Driver)

            self.test_normal_voltage_flash(action,Driver)

    
    @allure.severity('normal')
    @allure.title('用例标题：Boot数据传输到10%中断后发送1002')
    @allure.description('send 1002 after Boot transfer termination')
    def test_Boot_transfer_termination_1002(self,action,Driver):                   
        with allure.step('flash ternination when tansimit 10%'):
            iStep = 0
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size, skipapp=True,isContinue=False)
            i = 0
            while True:
                i +=1
                if (dl.app == True) and (dl.progress_number >= 10):
                    dl.set_stop(True)
                    break
                else:
                    time.sleep(1)
                if i == 1:
                    progress_number = dl.progress_number 
                if i > 80 and dl.progress_number == progress_number:
                    dl.set_stop(True)
                    break
            dl.join()

            iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 02', '50 02', 0, iStep)
            with assume: assert size > 0

            logging.info('Wait 30 seconds')
            time.sleep(30)
            dl.post_abnormal_termination_startup()

            self.checkPcanSignal(Driver)

            self.test_normal_voltage_flash(action,Driver)

    
    @allure.severity('normal')
    @allure.title('用例标题：Boot数据传输到10%中断后发送1003')
    @allure.description('send 1003 after Boot transfer termination')
    def test_Boot_transfer_termination_1003(self,action,Driver):                   
        with allure.step('flash ternination when tansimit 10%'):
            iStep = 0
            erash_startaddress = [0x00,0x05,0x00,0x00]
            erash_size = [0x00,0x08,0x4A,0x96]
            dl = Download(Driver['CAN'],Driver['UDS'],zipfile_path,erash_startaddress,erash_size, skipapp=True,isContinue=False)
            i = 0
            while True:
                i +=1
                if (dl.app == True) and (dl.progress_number >= 10):
                    dl.set_stop(True)
                    break
                else:
                    time.sleep(1)
                if i == 1:
                    progress_number = dl.progress_number 
                if i > 80 and dl.progress_number == progress_number:
                    dl.set_stop(True)
                    break
            dl.join()

            iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 03', '7F 10 7E', 0, iStep)
            with assume: assert size > 0

            logging.info('Wait 30 seconds')
            time.sleep(30)
            dl.post_abnormal_termination_startup()

            self.checkPcanSignal(Driver)

            self.test_normal_voltage_flash(action,Driver)


    # @allure.severity('normal')
    # @allure.title('用例标题：只升级boot')                             
    # @allure.description('only Flash app, flash failed!')
    # @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/62fc94a1cfaa81dc60bed3f3/cases')
    # def test_app_NotMach_boot(self,action,Driver):                   
    #     with allure.step('Flash by ship Flash Driver'):
    #         erash_startaddress = [0x00,0x05,0x00,0x00]
    #         erash_size = [0x00,0x08,0x4A,0x96]
    #         dl = Download(Driver['CAN'],Driver['UDS'],errorApp_path,erash_startaddress,erash_size,skipboot=True)
    #         dl.join()
    #         with assume: assert dl.success_flag == True
    #         self.restartMrr(Driver)
    #         dl.post_abnormal_termination_startup()
    #         with assume: assert dl.normal == True

    def restartMrr(self,Driver):
        for i in range(1):
            Driver['power'].set_vltage(0)
            time.sleep(1)
            Driver['power'].set_vltage(14)
            time.sleep(3)

    def checkPcanSignal(self,Driver):
        Driver['CAN2'].fush_q_buff()  # 清缓存
        time.sleep(1)
        ALl_data,buffer_size = Driver['CAN2'].read_frame()
        response_data_80 = ALl_data[ALl_data['AIdentifier']== 0x80]
        response_data_66F = ALl_data[ALl_data['AIdentifier']== 0x66F]

        count_80 = len(response_data_80)
        receive_data = []
        try:
            last_data = response_data_66F.iloc[0]['ADatas'] 
            for i in range (8):
                datai = last_data[i]
                receive_data.append(datai)
        except:
            last_data = []
        readstr = binascii.b2a_hex(bytearray(receive_data),' ')
        logging.info('receive_ID = [{0:X}], receive_Data = [{1}], count = [{2}]'.format(0x80,readstr, count_80))

        count_66F = len(response_data_66F)
        receive_data = []
        try:
            last_data = response_data_66F.iloc[0]['ADatas'] 
            for i in range (8):
                datai = last_data[i]
                receive_data.append(datai)
        except:
            last_data = []
        readstr = binascii.b2a_hex(bytearray(receive_data),' ')
        logging.info('receive_ID = [{0:X}], receive_Data = [{1}], count = [{2}]'.format(0x66F,readstr, count_66F))
        with assume: assert (count_66F > 0 or count_80 > 0)